<?php
// +----------------------------------------------------------------------
// | Created by PHPstorm: [ JRK丶Admin ]
// +----------------------------------------------------------------------
// | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
// +----------------------------------------------------------------------
// | SiteUrl: http://www.luckyhhy.cn
// +----------------------------------------------------------------------
// | Author: LuckyHhy <jackhhy520@qq.com>
// +----------------------------------------------------------------------
// | Date: 2020/6/26 0026
// +----------------------------------------------------------------------
// | Description:
// +----------------------------------------------------------------------

namespace app\admin\controller;


use app\admin\model\AdminUser;
use app\admin\model\AuthRule as AuthRules;
use app\admin\validate\CheckAdminUser;
use app\common\controller\AdminBaseController;
use app\common\model\personnel\PersonnelCourse;
use app\common\model\personnel\PersonnelStudent;
use app\common\model\personnel\PersonnelType;
use app\common\model\personnel\PersonnelYear;
use app\common\model\tang\SubjectList;
use app\common\service\GoogleAuthenticator;
use Jrk\Tree;
use think\Exception;
use app\common\model\tang\CostType as CostTypeModel;

class CostType extends AdminBaseController
{
    protected function initialize()
    {
        parent::initialize(); // TODO: Change the autogenerated stub
        $this->model = new CostTypeModel();
    }


    /**
     * @return mixed|string|\think\response\Json
     * @throws \think\db\exception\DbException
     * @author: Hhy <jackhhy520@qq.com>
     * @date: 2020/6/30 0030
     * @describe:添加编辑
     */
    public function add()
    {
        if (IS_AJAX) {
            $data = $this->request->post();
            $data['tax_code'] = $data['tax_sn'];
            if(!empty($data['auxiliary'])){
                $data['auxiliary'] = implode(',',$data['auxiliary']);
            }
            return $this->model->doAll($data);
        }
        $id = $this->request->param("id/d");//父id
        $info = $this->model->find($id);
        $cost_list = $this->model->where('pid','=',0)->field('id,cost_name')->select();
        //获取菜单列表
        $this->assign(compact("info", "id","cost_list"));
        return $this->fetch();
    }

    /**
     * @return string
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException  添加子菜单
     */
    public function addSon()
    {
        //获取菜单列表
        $tree = Tree::toFormatTree(AuthRules::menuList());
        $pid = $this->request->param("id/d");//父id
        $info = [];
        $this->assign("pid", $pid);
        $this->assign(compact("tree", "info"));
        return $this->fetch("auth_rule");
    }
    /**
     * 设置开票备注
     */
    public function remark()
    {
        $sendModel = (new \app\common\model\tang\SendConfig());
        if (IS_AJAX) {
            $param = $this->request->param();
            $sendModel = $sendModel->update([
                'remark' => $param['remark']
            ], ['id' => 1]);
            return self::ajaxResult([], 0, 1, '修改成功');
        }
        $remark = $sendModel->value('remark');
        //获取菜单列表
        $this->assign(compact("remark"));
        return $this->fetch();
    }
}